<?php
/*
 * Copyright (c) 2022.  Liuhongbin All rights reserved.
 * @domain http://dkyx.cc
 * @author liuhongbin <514660094@qq.com>
 */

/**
 * @Author: liuhongbin
 * @Email: 514660094@qq.com
 * @Date: 2019-02-12 16:15:10
 * @Description:
 * @LastEditors: liuhongbin
 * @LastEditTime: xxx
 */

namespace app\listener;


use think\facade\Cache;

class Timer
{
    public $key = 'listener_timer_';

    public $times = [5, 10, 60];

    public function handle(): void
    {
        foreach ($this->times as $k => $value) {
            $key = $this->key . $value;
            $time = Cache::get($key) ?? 0;
            if (time() - $time > $value) {
                Cache::set($key, time());
                // 存在应用名称
                if (get_addon(false,false,false)) {
                    event('onTimer_' . $value);
                }
                event('onGlobalTimer_' . $value);
            }
        }
    }
}
